using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
    public static SceneLoader Instance { get; private set; }

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    // 场景名称常量
    public const string MAIN_MENU_SCENE = "MainMenu";
    public const string NUMBER_PUZZLE_SCENE = "NumberPuzzle";
    public const string MEMORY_MATCH_SCENE = "MemoryMatch";
    public const string TETRIS_SCENE = "Tetris";
    public const string CONNECT_CLEAR_SCENE = "ConnectClear";

    // 加载主菜单
    public void LoadMainMenu()
    {
        SceneManager.LoadScene(MAIN_MENU_SCENE);
    }

    // 加载指定游戏场景
    public void LoadGame(GameManager.GameType gameType)
    {
        string sceneName = GetSceneNameForGameType(gameType);
        if (!string.IsNullOrEmpty(sceneName))
        {
            SceneManager.LoadScene(sceneName);
        }
    }

    // 根据游戏类型获取场景名称
    private string GetSceneNameForGameType(GameManager.GameType gameType)
    {
        switch (gameType)
        {
            case GameManager.GameType.NumberPuzzle:
                return NUMBER_PUZZLE_SCENE;
            case GameManager.GameType.MemoryMatch:
                return MEMORY_MATCH_SCENE;
            case GameManager.GameType.Tetris:
                return TETRIS_SCENE;
            case GameManager.GameType.ConnectClear:
                return CONNECT_CLEAR_SCENE;
            default:
                return string.Empty;
        }
    }
}
